package com.zy.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zy.mapper.ManMapper;
import com.zy.pojo.Management;
import com.zy.vo.ManagementVo;
import com.zy.vo.PageVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service("ManService")
public class ManServiceImpl extends ServiceImpl<ManMapper, Management> implements ManService{
    @Resource
    private ManMapper manMapper;
    @Override
    public List<Management> getManagement(ManagementVo managementVo) {
        QueryWrapper queryWrapper =new QueryWrapper();
        queryWrapper.like(!StringUtils.isEmpty(managementVo.getUserCode()),"user_Code",managementVo.getUserCode())
                .gt(managementVo.getStime()!=null,"user_Date",managementVo.getStime())
                .lt(managementVo.getEtime()!=null,"user_Date",managementVo.getEtime());
        return super.list(queryWrapper);
    }

    @Override
    public PageVo getPage(Integer pageNo, Integer pageSize, ManagementVo managementVo) {
        Page page =new Page();
        page.setSize(pageSize);
        page.setCurrent(pageNo);
        QueryWrapper queryWrapper =new QueryWrapper();
        queryWrapper.like(!StringUtils.isEmpty(managementVo.getUserCode()),"user_Code",managementVo.getUserCode())
                .gt(managementVo.getStime()!=null,"user_Date",managementVo.getStime())
                .lt(managementVo.getEtime()!=null,"user_Date",managementVo.getEtime());
        List<Management> list =manMapper.getManagement(page,queryWrapper);
        return new PageVo(list,page.getTotal());
    }

    @Override
    public void add(Management management) {

        manMapper.insert(management);
    }

    @Override
    public void update(Management management) {
        manMapper.updateById(management);
    }

    @Override
    public void delete(Integer id) {
    manMapper.deleteById(id);
    }
}
